package com.catering.controller;

import com.catering.config.Result;
import com.catering.pojo.Appointment;
import com.catering.pojo.DOrder;
import com.catering.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/appointment")
public class AppointmentController {
    @Autowired
    private AppointmentService appointmentService;

    @PostMapping("/check")
    public Result check(@RequestBody Map<String, String> params) {
        String phone = params.get("phone");
        String date = params.get("date");

        if (phone == null || phone.trim().isEmpty()) {
            return Result.error("手机号不能为空");
        }

        boolean hasAppointment = appointmentService.checkTodayAppointment(phone);

        Map<String, Object> data = new HashMap<>();
        data.put("phone", phone);
        data.put("data", hasAppointment);

        return Result.success(data);
    }

    @GetMapping("/detail/{id}")
    public Result getAppointmentDetail(@PathVariable Integer id) {
        if (id == null) {
            return Result.error("订单ID不能为空");
        }

        Appointment appointment = appointmentService.getAppointmentById(id);
        if (appointment == null) {
            return Result.error("未找到预约信息");
        }

        return Result.success(appointment);
    }

}
